package com.ruoyi.controller.production;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.production.MesProcess;
import com.ruoyi.service.production.IMesProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工序Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/production/process")
public class MesProcessController extends BaseController
{
    @Autowired
    private IMesProcessService IMesProcessService;

    /**
     * 查询工序列表
     */
    @PreAuthorize("@ss.hasPermi('production:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesProcess mesProcess)
    {
        startPage();
        List<MesProcess> list = IMesProcessService.selectMesProcessList(mesProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序列表
     */
    @PreAuthorize("@ss.hasPermi('production:process:export')")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProcess mesProcess)
    {
        List<MesProcess> list = IMesProcessService.selectMesProcessList(mesProcess);
        ExcelUtil<MesProcess> util = new ExcelUtil<MesProcess>(MesProcess.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:process:query')")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(IMesProcessService.selectMesProcessByProcessId(processId));
    }

    /**
     * 根据工艺路线ID查询工序列表
     */
    @GetMapping("/route/{routeId}")
    public AjaxResult getProcessByRouteId(@PathVariable("routeId") Long routeId)
    {
        List<MesProcess> list = IMesProcessService.selectMesProcessListByRouteId(routeId);
        return success(list);
    }

    /**
     * 新增工序
     */
    @PreAuthorize("@ss.hasPermi('production:process:add')")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProcess mesProcess)
    {
        return toAjax(IMesProcessService.insertMesProcess(mesProcess));
    }

    /**
     * 修改工序
     */
    @PreAuthorize("@ss.hasPermi('production:process:edit')")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProcess mesProcess)
    {
        return toAjax(IMesProcessService.updateMesProcess(mesProcess));
    }

    /**
     * 删除工序
     */
    @PreAuthorize("@ss.hasPermi('production:process:remove')")
    @Log(title = "工序", businessType = BusinessType.DELETE)
    @DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(IMesProcessService.deleteMesProcessByProcessIds(processIds));
    }
}